package gameserver.model.templates.item;

import java.util.TreeSet;

import gameserver.model.gameobjects.Gender;
import gameserver.model.gameobjects.stats.modifiers.StatModifier;
import gameserver.model.templates.stats.ModifiersTemplate;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "item_templates")
public class ItemTemplate
{
	@XmlAttribute(name = "id", required = true)
    @XmlID
	private String id;
	
	@XmlElement(name = "modifiers", required = false)
    protected ModifiersTemplate modifiers;
	
	@XmlAttribute(name = "name")
	private String name;
	
	@XmlAttribute(name = "item_category")
	private ItemCategory itemCategory;
	
	@XmlAttribute(name = "price")
	private int price;
	
	@XmlAttribute(name = "description")
	private String desc;
	
	@XmlAttribute(name = "gender")
	private int genderPermitted;
	
	@XmlAttribute(name = "level")
	private int level;
	
	@XmlAttribute(name = "expire_mins", required = false)
    private int expireMins;
	
	private int itemId;

	public TreeSet<StatModifier> getModifiers()
	{
		if (modifiers != null) {
            return modifiers.getModifiers();
        } else {
            return null;
        }
	}



	public String getName()
	{
		return name;
	}



	public ItemCategory getItemCategory()
	{
		return itemCategory;
	}



	public int getPrice()
	{
		return price;
	}



	public String getDesc()
	{
		return desc;
	}



	public int getGenderPermitted()
	{
		return genderPermitted;
	}



	public int getLevel()
	{
		return level;
	}



	public int getExpireMins()
	{
		return expireMins;
	}



	public int getTemplateId()
	{
		return itemId;
	}



	public boolean isAllowFor(Gender _gender,int _level)
	{
		boolean allowed = _gender.getValue() == genderPermitted;
		allowed = level<=_level;
		return allowed;
	}
	
	public void setItemId(int itemId) {
        this.itemId = itemId;
    }
	
	
	void afterUnmarshal(Unmarshaller u,Object parent)
	{
		setItemId(Integer.parseInt("id"));
		
	}
	
}
